# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Jonahtan Schaeffer <joschaeffer@gmail.com>
# COntributor: Drake Arconis <lightdrake@gmail.com>

pkgbase=jsoncpp
pkgname=('jsoncpp' 'jsoncpp-doc')
pkgver=1.8.1
pkgrel=1
pkgdesc='C++ library for interacting with JSON'
url='https://github.com/open-source-parsers/jsoncpp'
arch=('i686' 'x86_64')
license=('MIT' 'custom:Public_Domain')
makedepends=('gcc-libs' 'cmake' 'doxygen' 'graphviz' 'python')
options=('staticlibs')
source=(${pkgbase}-${pkgver}.tar.gz::https://github.com/open-source-parsers/${pkgbase}/archive/${pkgver}.tar.gz)
sha512sums=('4203826fca4c366b51d28ffc928399c914ffaba8be1cada64ff118b5742e6b469d3fc3e59344587d851447857b479794c5697d4fd11a9a55b32a3a7a801b745b')

prepare() {
  cd ${pkgbase}-${pkgver}
  mkdir -p build
}

build() {
  cd ${pkgbase}-${pkgver}
  python doxybuild.py --with-dot

  cd build
  cmake \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_STATIC_LIBS=ON \
    ..
  make
}

check() {
  cd ${pkgbase}-${pkgver}/build
  make test jsoncpp_test jsoncpp_readerwriter_tests
}

package_jsoncpp() {
  depends=('gcc-libs')
  optdepends=('jsoncpp-doc: documentation')

  cd ${pkgbase}-${pkgver}
  make -C build DESTDIR="${pkgdir}" install
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -Dm 644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}"
}

package_jsoncpp-doc() {
  pkgdesc+=' (documentation)'
  optdepends=('jsoncpp')

  cd ${pkgbase}-${pkgver}
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -dm 755 "${pkgdir}/usr/share/doc/${pkgbase}"
  cp -a dist/doxygen/jsoncpp-api-html-${pkgver} "${pkgdir}/usr/share/doc/${pkgbase}/html"
}

# vim: ts=2 sw=2 et:
